<?php
/**
 * Created by PhpStorm.
 * 商家冻结账户操作记录
 * User: caicm
 * Date: 2017/6/29
 * Time: 17:32
 */

namespace WMApi\Model;


use Think\Model;

class WmSellerFreezeRecordModel extends Model {

    /**
     * 写入冻结操作记录
     * Created By caicm
     * @param int $seller_id 商家id
     * @param int $withdraw_record_id 提现记录id
     * @param int $money 操作金额
     * @param int $freeze_money 冻结金额（操作后的冻结金额）
     * @param string $record_note 记录备注
     * @return mixed
     */
    public function add_record($seller_id=0, $withdraw_record_id=0, $money=0, $freeze_money=0, $record_note=''){

        $data = array(
            'seller_id' => $seller_id,
            'withdraw_record_id' => $withdraw_record_id,
            'money' => $money,
            'freeze_money' => $freeze_money,
            'record_note' => $record_note,
            'type' => 1,
            'account_type' => 1,
            'add_time' => gmtime()
        );

        return $this->data()->add($data);

    }

    /**
     * 获取商家冻结账户操作记录列表
     * Created By caicm
     * @param int $seller_id
     * @param $limit
     * @return mixed
     */
    public function find_record_list($seller_id=0, $limit){

        $where = array(
            'seller_id' => $seller_id
        );

        $field = 'id,withdraw_record_id,type,account_type,money,freeze_money,add_time';


        return $this->field($field)->where($where)->order('id desc')->limit($limit)->select();
    }

    /**
     * 获取商家冻结账户操作记录数量
     * Created By caicm
     * @param int $seller_id
     * @return mixed
     */
    public function find_record_count($seller_id=0){

        $where = array(
            'seller_id' => $seller_id
        );

        return $this->where($where)->count('id');
    }
}